import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDUnitLv {
	/**等级*/
	id,
	/**初始1级，升到2级读取1级的需求--经验值，满级配置-1*/
	exp,
	/**战斗数值*/
	math,
	/**天赋点*/
	talentPoint,
	/**触发活动id*/
	activityTigger,

	/**枚举数量*/
	EnumCount
}



export class CDUnitLv{
	/**等级*/
	public id: number;
	/**初始1级，升到2级读取1级的需求--经验值，满级配置-1*/
	public exp: number;
	/**战斗数值*/
	public math: number;
	/**天赋点*/
	public talentPoint: number;
	/**触发活动id*/
	public activityTigger: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDUnitLv.id: return this.id;
			case E_CDUnitLv.exp: return this.exp;
			case E_CDUnitLv.math: return this.math;
			case E_CDUnitLv.talentPoint: return this.talentPoint;
			case E_CDUnitLv.activityTigger: return this.activityTigger;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDUnitLv.id: this.id = v; break;
			case E_CDUnitLv.exp: this.exp = v; break;
			case E_CDUnitLv.math: this.math = v; break;
			case E_CDUnitLv.talentPoint: this.talentPoint = v; break;
			case E_CDUnitLv.activityTigger: this.activityTigger = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDUnitLv> = new HashMap<number, CDUnitLv>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDUnitLv[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDUnitLv();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].exp = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].math = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].talentPoint = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].activityTigger = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDUnitLv{
		return this.datas ? this.datas.get(id) : null;
	}
}
